import 'package:fluro/fluro.dart';
import 'package:mvvm_provider/page/mine/view_model/mine_detai_like_view_model.dart';
import 'package:mvvm_provider/page/mine/view_model/mine_detai_type2l_view_model.dart';
import 'package:mvvm_provider/page/mine/view_model/mine_detail_view_model.dart';
import 'package:mvvm_provider/page/novel/view_model/novel_detail_view_model.dart';
import 'package:provider/provider.dart';
import '../page/mine/view/mine_detail_page.dart';
import '../page/mine/view/mine_detail_type2_page.dart';
import '../page/novel/view/novel_detail_page.dart';
import 'irouter_provider.dart';

class MineRouter extends IRouterProvider {
  static const mineDetailPage = "/pages/mine/view/mine_detail_page"; //资讯详情
  static const mineDetailType2Page = "/pages/mine/view/mine_detail_type2_page"; //资讯详情2
  static const novelDetailPage = "/page/novel/view/novel_detail_page"; //小说详情

  @override
  void initRouter(FluroRouter router) {
    router.define(mineDetailPage, handler: Handler(handlerFunc: (context, params) {
      Map? argument = context!.settings!.arguments as Map?;
      int entityId = argument?['entityId'] ?? 0;
      return ChangeNotifierProvider<MineDetailViewModel>(
        create: (_) => MineDetailViewModel(),
        builder: (context, widget) {
          return MineDetailPage(
            entityId: entityId,
          );
        },
      );
    }));

    router.define(mineDetailType2Page, handler: Handler(handlerFunc: (context, params) {
      Map? argument = context!.settings!.arguments as Map?;
      int entityId = argument?['entityId'] ?? 0;
      return MultiProvider(
          providers: [
            ChangeNotifierProvider<MineDetailType2ViewModel>(
                create: (_) => MineDetailType2ViewModel()),
            ChangeNotifierProvider<MineDetailLikeViewModel>(
                create: (_) => MineDetailLikeViewModel()),
          ],
          child: MineDetailType2Page(
            entityId: entityId,
          ));
    }));

    router.define(novelDetailPage, handler: Handler(handlerFunc: (context, params) {
      return ChangeNotifierProvider<NovelDetailViewModel>(
          create: (_) => NovelDetailViewModel(),
          builder: (context, widget) {
            return const NovelDetailPage();
          });
    }));
  }
}
